package action;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Comparator;
import java.util.List;

import comparetor.CustomerComparetorByBirth;
import comparetor.CustomerComparetorById;
import pojo.Customer;
import processor.DataProcessor;
import processor.impl.DataProcessorImpl;
import scanner.DataScanner;
import scanner.impl.DataScannerImpl;

public class DataProcessAction {
	private Comparator<Customer> comparator;
	private DataProcessor dp;						//输入list<Coustomer>,比较器，format,返回输出xml或数据
	private DataScanner scanner;					//输入filepath,读数据，校验，封装成对象，返回对象List
	private List<Customer> list;
	private String format;
	
	public DataProcessAction() throws FileNotFoundException {
		DataScanner scanner=new DataScannerImpl(new FileInputStream("test.properties"));
		Comparator<Customer> comparator=new CustomerComparetorById();
		list=scanner.scan();
	}


	public void action() throws Exception{
		format="xml";
		DataScanner scanner=new DataScannerImpl(new FileInputStream("test.properties"));
		//comparator=new CustomerComparetorByBirth();
		comparator=new CustomerComparetorById();
		dp=new DataProcessorImpl(list, format);             
		StringBuilder sb=dp.process(comparator);		//输入list<Coustomer>,比较器，format（选择打印的方式）,返回输出String(xml或显示数据）	
														//Analysor和printer直接在里面实现
		//System.out.println(sb.toString());
	}
	
	public StringBuilder action1(String format, Comparator<Customer> comp) throws Exception{
		dp=new DataProcessorImpl(list, format);             
		StringBuilder sb=dp.process(comp);		//输入list<Coustomer>,比较器，format（选择打印的方式）,返回输出String(xml或显示数据）	
		return sb;
	}
	
	public static void main(String[] args) throws Exception{
		new DataProcessAction().action();
	}
}
